package ru.acme.lab12.domain.bank;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Collections;

import ru.acme.lab12.domain.client.Client;
import ru.acme.lab12.domain.client.ClientRegistrationListener;
import ru.acme.lab12.domain.client.ImmutableClient;

public class Bank implements ImmutableBank {
	
	private List<Client> clients = new ArrayList<Client>(); 
	private List<ClientRegistrationListener> listeners = new ArrayList<ClientRegistrationListener>(); 
			
	class DebugListener implements ClientRegistrationListener {
		public void onClientAdded(Client client) {
			System.out.println(client.toString() + ", " + new Date());
		}
	}
	public static class EmailNotificationListener implements ClientRegistrationListener {
		public void onClientAdded(Client client) {
			System.out.println("Email notification to be sent");
		}
	}
	public static class PrintClientListener implements ClientRegistrationListener {
		public void onClientAdded(Client client) {
			System.out.println(client.getClientSalutation());
		}
	}

	public Bank() {
		this.listeners.add(new DebugListener());
	}
	
	public Bank(ClientRegistrationListener[] listeners) {
		this.listeners.add(new DebugListener());
		if (listeners != null) {
			for (ClientRegistrationListener listener : listeners) {
				this.listeners.add(listener);
			}
		}
	}
	
	public void addClient(Client client) {
		clients.add(client);
		for (ClientRegistrationListener listener : listeners) {
			listener.onClientAdded(client);
		}
	}

	public List<? extends ImmutableClient> getImmutableClients() {
		return Collections.unmodifiableList(clients);
	}

	public List<Client> getClients() {
		return Collections.unmodifiableList(clients);
	}

	public void addListener(ClientRegistrationListener listener) {
		listeners.add(listener);
	}

}
